Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-13477: scanner for DocumentDB #4

Merged
merged 3 commits into from
Feb 12, 2024
Merged

Conversation

ricardorey10
Copy link
Contributor

@ricardorey10 ricardorey10 commented Feb 8, 2024

Description of the change

This just implements the Scanner logic for DocumentDB repositories.

Type of change

  • Bug fix (non-breaking change that fixes an issue).
  • New feature (non-breaking change that adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklists

Development

  • Lint rules pass locally.
  • The code changed/added as part of this pull request has been covered with tests.
  • All tests related to the changed code pass.

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached.
  • Jira issue referenced in commit message and/or PR title.

Testing

Unit + integration tests.

@ricardorey10 ricardorey10 marked this pull request as ready for review February 9, 2024 05:29
aws/client.go Outdated
type docdbCluster struct {
arn string
creationDate time.Time
cluster docdbTypes.DBCluster
instances []docdbTypes.DBInstance
tags []string
}

func (c *awsClient) getDocumentDBClusters(
ctx context.Context,
) ([]docdbCluster, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe all we need here are the clusters and the tags directly associated to them. Based on what we briefly discussed today, there's a field (DBClusterMembers) in the cluster object that contains basic information about the cluster's instances (instance name, if its writer or not, etc) and that should be enough information. CC @yoursnerdly @ccampo133 to make sure we agree on that.

If you look at the getRDSClusters, it has a similar structure and all it does is fetch and return a list of clusters. I would suggest this function to follow a similar approach, the only difference I see here is that for DocumentDB we will need to call this other API to fetch the cluster tags. In this case, the docdbCluster could be updated to:

Suggested change
type docdbCluster struct {
arn string
creationDate time.Time
cluster docdbTypes.DBCluster
instances []docdbTypes.DBInstance
tags []string
}
func (c *awsClient) getDocumentDBClusters(
ctx context.Context,
) ([]docdbCluster, error) {
type docdbCluster struct {
cluster docdbTypes.DBCluster
tags []string
}
func (c *awsClient) getDocumentDBClusters(
ctx context.Context,
) ([]docdbCluster, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Done.

Make sure unit and integration tests pass

Use aws.String() for string pointers

Address review comments
Copy link
Contributor

@VictorGFM VictorGFM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardorey10 just added a few comments below that we need to consider before merging this PR

aws/client.go Outdated
Comment on lines 63 to 67
DescribeDBInstances(
ctx context.Context,
params *docdb.DescribeDBInstancesInput,
optFns ...func(*docdb.Options),
) (*docdb.DescribeDBInstancesOutput, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're no longer using the DescribeDBInstances this can be removed.

Suggested change
DescribeDBInstances(
ctx context.Context,
params *docdb.DescribeDBInstancesInput,
optFns ...func(*docdb.Options),
) (*docdb.DescribeDBInstancesOutput, error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I thought we had decided to keep all instance tags too, but in order to be more consistent with RDS I agree we should get rid of this.

aws/client.go Outdated
clusterARN := clusters[i].DBClusterArn
var marker *string
for {
output, err := c.docdb.DescribeDBInstances(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to retrieve the cluster instances, since we are not returning it anymore. Same for instances tags. Like I mentioned in my previous comment, I believe just getting the cluster tags here should be enough.

Type: scan.RepoTypeDocumentDB,
CreatedAt: *cluster.cluster.ClusterCreateTime,
Tags: cluster.tags,
Properties: cluster.cluster.DBClusterMembers,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Properties should be the whole cluster object instead of just the cluster members. Similar to how its done in newRepositoryFromRDSCluster.

Suggested change
Properties: cluster.cluster.DBClusterMembers,
Properties: cluster.cluster,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@VictorGFM VictorGFM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

aws/client.go Outdated

// Phew, that was a lot of work, but we have all that we wanted:
// All clusters in the <clusters> variable
// A map from cluster ARN to instances, in the <instances> variable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// A map from cluster ARN to instances, in the <instances> variable

@ricardorey10 ricardorey10 merged commit 60ac5dc into main Feb 12, 2024
1 check passed
@ricardorey10 ricardorey10 deleted the feature/ENG-13477/docdb branch February 12, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants